package com.decheng.controller;

import com.decheng.form.UserLoginForm;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.validation.Valid;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/6/30
 */
@Controller
public class UserController {

    @GetMapping("/login")
    public String toLoginPage(Model model) {
        model.addAttribute("userLoginForm", new UserLoginForm());
        return "user/login";
    }

    @PostMapping("/login")
    public String doLogin(@Valid UserLoginForm userLoginForm, BindingResult result) {
        if (result.hasErrors()) {
            return "user/login";
        }
        return "redirect:/index";
    }
}
